package com.atguigu.marketing.controller;


import com.atguigu.marketing.bean.MarketingRuleChannelModel;
import com.atguigu.marketing.service.MarketingRuleChannelModelService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;

/**
 * <p>
 * 营销规则-渠道模板 前端控制器
 * </p>
 *
 * @author zhangchen
 * @since 2023-02-02
 */
@RestController
@RequestMapping("/channel-model")
public class MarketingRuleChannelModelController {


    @Autowired
    MarketingRuleChannelModelService marketingRuleChannelModelService;


    @GetMapping("/list")
    @CrossOrigin
    public List<MarketingRuleChannelModel>  getMarketingRuleChannelModel(){
        List<MarketingRuleChannelModel> smsModeList = marketingRuleChannelModelService.list(new QueryWrapper<MarketingRuleChannelModel>().orderByDesc("id"));
        return smsModeList;
    }

    @CrossOrigin
    @GetMapping("/detail/{id}")
    public MarketingRuleChannelModel getMarketingRuleChannelModel(@PathVariable("id") String id){
        MarketingRuleChannelModel channelModel = marketingRuleChannelModelService.getById(id);
        return channelModel;
    }

    @CrossOrigin
    @PostMapping("/detail")
    public String saveMarketingRuleChannelModelSms(@RequestBody MarketingRuleChannelModel marketingRuleChannelModel){
        if(marketingRuleChannelModel.getId()==null){
            marketingRuleChannelModel.setCreateTime(new Date());
        }else{
            marketingRuleChannelModel.setUpdateTime(new Date());
        }
        marketingRuleChannelModelService.saveOrUpdate(marketingRuleChannelModel);
        return "success";
    }


}

